﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Helper="clr-namespace:BusinessManager.Helps">

    <Helper:StringFormatForIDConverter x:Key="stringFormatForIDConverter"/>

    <SolidColorBrush x:Key="ComboBox_BorderColor">#FFC2C2C2</SolidColorBrush>
    <SolidColorBrush x:Key="ComboBox_BgColor">White</SolidColorBrush>
    <SolidColorBrush x:Key="ComboBox_FgColor">#FF505356</SolidColorBrush>

    <SolidColorBrush x:Key="ComboBox_Enable_BgColor">#FFF1F1F1</SolidColorBrush>
    <SolidColorBrush x:Key="ComboBox_Enable_BorderColor">#FF808080</SolidColorBrush>
    <SolidColorBrush x:Key="ComboBox_Enable_FgColor">#FF808080</SolidColorBrush>

    <SolidColorBrush x:Key="ComboBox_NoEditable_BgColor">#FFF1F1F1</SolidColorBrush>
    <SolidColorBrush x:Key="ComboBox_Editable_BgColor">White</SolidColorBrush>

    <SolidColorBrush x:Key="ComboBoxItem_MouseOver_BgColor">#FF1280F5</SolidColorBrush>
    <SolidColorBrush x:Key="ComboBoxItem_MouseOver_FgColor">White</SolidColorBrush>


    <Geometry x:Key="DownArrowGeometry">M 0 0 L 3.5 4 L 7 0 Z</Geometry>

    <Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
        <Setter Property="Cursor" Value="Hand"/>
        <Setter Property="BorderBrush" Value="{x:Null}"/>
        <Setter Property="Background" Value="#00000000"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border x:Name="bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
                        <Grid HorizontalAlignment="Right" Width="20" Background="{x:Null}">
                            <Border x:Name="border">
                                <Path x:Name="Arrow" Width="8" Height="5" Data="{StaticResource DownArrowGeometry}" Fill="{Binding Foreground,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ComboBox}}}" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Fill"/>
                            </Border>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Setter Property="Fill" TargetName="Arrow" Value="#FFF0541A"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" SourceName="bd" Value="true">
                            <Setter Property="Fill" TargetName="Arrow" Value="#FFF0541A"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
        <Border SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1">
            <Grid x:Name="Placement" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TextBox x:Name="PART_EditableTextBox" Background="#00FFFFFF" FontSize="{TemplateBinding FontSize}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{TemplateBinding IsReadOnly}" Margin="1,3,0,3" Style="{StaticResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                <ToggleButton x:Name="toggleButton" Grid.Column="1" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
                <Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{TemplateBinding IsDropDownOpen}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
                    <Border x:Name="DropDownBorder" Background="{TemplateBinding Background}" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=Placement}">
                        <ScrollViewer CanContentScroll="true">
                            <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </ScrollViewer>
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="HasItems" Value="false">
                <Setter Property="Height" TargetName="DropDownBorder" Value="95"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type ComboBox}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>  
        <Setter Property="Foreground" Value="{StaticResource ComboBox_FgColor}"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="FontSize" Value="14"/>
        <Setter Property="Background" Value="{StaticResource ComboBox_BgColor}"/>
        <Setter Property="BorderBrush" Value="{StaticResource ComboBox_BorderColor}"/>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBox}">
                    <Border  Background="{StaticResource ComboBox_NoEditable_BgColor}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" SnapsToDevicePixels="true">
                        <Grid x:Name="MainGrid">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
                            </Grid.ColumnDefinitions>
                            <ToggleButton x:Name="toggleButton" FontSize="{TemplateBinding FontSize}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
                            <ContentPresenter ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"  IsHitTestVisible="false" Margin="5,0,8,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            <Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{TemplateBinding IsDropDownOpen}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
                                <Border x:Name="DropDownBorder" Background="{TemplateBinding Background}" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}">
                                    <ScrollViewer CanContentScroll="true">
                                        <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                    </ScrollViewer>
                                </Border>
                            </Popup>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasItems" Value="false">
                            <Setter Property="Height" TargetName="DropDownBorder" Value="95"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Background" Value="{StaticResource ComboBox_Enable_BgColor}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </Trigger>
            <Trigger Property="IsEditable" Value="true">
                <Setter Property="Padding" Value="3"/>
                <Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Background" Value="{StaticResource ComboBox_Enable_BgColor}"/>
                <Setter Property="Foreground" Value="{StaticResource ComboBox_Enable_FgColor}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="ComboBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                    <Border x:Name="Bd" SnapsToDevicePixels="true" Padding="3,0" Background="#00000000" Height="{Binding Height,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}}">
                        <ContentPresenter x:Name="contentPresenter"  
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                            VerticalAlignment="Center" 
                            HorizontalAlignment="{Binding HorizontalContentAlignment,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}}"
                            />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource ComboBoxItem_MouseOver_BgColor}"/>
                            <Setter Property="Foreground" Value="{StaticResource ComboBoxItem_MouseOver_FgColor}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="EmployeeComboBoxItem" TargetType="ComboBoxItem">
        <Setter Property="ToolTip" Value="{Binding ID,Converter={StaticResource stringFormatForIDConverter}}"/> 
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                    <Border x:Name="Bd" SnapsToDevicePixels="true" Padding="3,0" Background="#00000000" Height="{Binding Height,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}}">
                        <ContentPresenter x:Name="contentPresenter"  
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                            VerticalAlignment="Center" 
                            HorizontalAlignment="{Binding HorizontalContentAlignment,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}}"
                            />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource ComboBoxItem_MouseOver_BgColor}"/>
                            <Setter Property="Foreground" Value="{StaticResource ComboBoxItem_MouseOver_FgColor}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>